package com.koron.tool.convertor;

import com.koron.tool.bean.ToolInventoryReportBean;
import com.koron.tool.bean.dto.InventoryReportDetailDto;
import com.koron.tool.enums.InventorySituationEnum;
import com.koron.tool.enums.InventoryStatusEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author: laiguangming
 * @Date: 2022/10/10 15:56
 */
@Mapper
public interface InventoryReportDetailConvertor {

    InventoryReportDetailConvertor INSTANCE = Mappers.getMapper(InventoryReportDetailConvertor.class);

    @Mappings({
            @Mapping(target = "model", defaultValue = "-"),
            @Mapping(source = "startStatus", target = "startStatus", qualifiedByName = "inventoryStatusMapper"),
            @Mapping(source = "endStatus", target = "endStatus", qualifiedByName = "inventoryStatusMapper"),
            @Mapping(source = "inventorySituation", target = "inventorySituation", qualifiedByName = "inventorySituationMapper"),
            @Mapping(target = "inventoryPerson", defaultValue = "-"),
            @Mapping(source = "inventoryTime", target = "inventoryTime", qualifiedByName = "inventoryTimeFormatter")
    })
    InventoryReportDetailDto toInventoryReportDetailDto(ToolInventoryReportBean bean);

    List<InventoryReportDetailDto> toInventoryReportDetailDtoList(List<ToolInventoryReportBean> bean);

    /**
     * 映射库存状态
     * @param inventoryStatus
     * @return
     */
    @Named("inventoryStatusMapper")
    static String inventoryStatusMapper(String inventoryStatus) {
        return InventoryStatusEnum.getMap().get(inventoryStatus);
    }

    /**
     * 映射盘点状态
     * @param inventorySituation
     * @return
     */
    @Named("inventorySituationMapper")
    static String inventorySituationMapper(String inventorySituation) {
        return InventorySituationEnum.getMap().get(inventorySituation);
    }

    /**
     * 格式化时间
     * @param timeStamp
     * @return
     */
    @Named("inventoryTimeFormatter")
    static String inventoryTimeFormatter(Long timeStamp) {
        if (timeStamp == null) {
            return "-";
        } else {
            return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(timeStamp * 1000);
        }
    }

}
